package cn.cycleif.enums;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum OpTypeEnum implements IEnum<Integer> {
  ADD(0, "新增", "add"),
  UPDATE(1, "修改", "update"),
  DELETE(2, "删除", "delete");

  private final int    code;
  @JsonValue
  private final String desc;
  private final String sign;

  OpTypeEnum(int code, String desc, String sign) {
    this.code = code;
    this.desc = desc;
    this.sign = sign;
  }

  public static OpTypeEnum fromCode(Integer code) {
    for (OpTypeEnum typeEnum : OpTypeEnum.values()) {
      if (typeEnum.getValue()
                  .equals(code)) {
        return typeEnum;
      }
    }
    return null;
  }

  @Override
  public Integer getValue() {
    return this.code;
  }
}
